package com.dongjiantong.biz.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.biz.mapper.DjtFarmsStockFormsMapper;
import com.dongjiantong.biz.model.DjtFarmsStockForms;
import com.dongjiantong.biz.service.DjtFarmsStockFormsService;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.exceptions.OPServerException;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by ThinkPad on 2017/11/20.
 */
@Slf4j
@Service(version = "1.0.0")
public class DjtFarmsStockFormsServiceImpl extends ServiceMybatis<DjtFarmsStockForms> implements DjtFarmsStockFormsService {
    @Resource
    private DjtFarmsStockFormsMapper djtFarmsStockFormsMapper;

    /**
     * todo 根据 区域和 和养殖类型查询最近的几天的存栏变化
     *
     * @param map animal_type ,area_code  , limit
     * @return
     */
    @Override
    public List<Map> findByTypeAndArea(Map<String, Object> map) {
        try {
            List<Map> list = djtFarmsStockFormsMapper.findByTypeAndArea(map);
            if (list == null) {
                log.error("find stock quantity by type(type = {}) is not found", map);
                throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR, "存栏没有找到");
            }


            return list;
        } catch (Exception e) {
            log.error("find stock quantity by type(type = {}) is not found cause:{}", map, Throwables.getStackTraceAsString(e));
            throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR, "查询出错，请稍后再试");
        }
    }

}
